package com.eclink.asset.asset.service;

import cn.hutool.core.bean.BeanUtil;
import com.eclink.asset.asset.domain.dto.DataReportAssetCategoryDTO;
import com.eclink.asset.domain.AssetCategory;
import com.eclink.asset.service.AssetCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 资产数据报表的服务
 */
@Service
public class AssetDataReportCategoryService {

    @Resource
    private AssetCategoryService assetCategoryService;

    @Resource
    private AssetItemService assetItemService;

    public List<DataReportAssetCategoryDTO> list() {
        List<AssetCategory> categoryList = assetCategoryService.selectListAll();
        List<DataReportAssetCategoryDTO> res = new ArrayList<>();
        for (AssetCategory category : categoryList) {
            Long categoryId = category.getId();
            DataReportAssetCategoryDTO dto = new DataReportAssetCategoryDTO();
            BeanUtil.copyProperties(category, dto);
            dto.setCount(assetItemService.getCount(categoryId));
            dto.setBuyPrice(assetItemService.getSum(categoryId));
            res.add(dto);
        }
        return res;
    }

}
